<?php
namespace app\api\controller;
use think\Request;
use app\base\model\Order;
class Pay extends Base{
    //订单模型
    protected $order;
    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $this->order = new Order();
        require_once APP_PATH . '/../vendor/alipay/config.php';
        require_once APP_PATH.'/../vendor/alipay/pagepay/service/AlipayTradeService.php';
        require_once APP_PATH.'/../vendor/alipay/pagepay/buildermodel/AlipayTradePagePayContentBuilder.php';
    }
    public function pagePay(){
     /*   if(empty($this->userInfo)){
            $msg['message']=checkMsg(LOGIN_ERROR);
            return $msg;
        }*/
      //  $order_id = $this->request->post('order_id');
        $order_id = 4;
        if(empty($order_id)){
            $msg['message']=checkMsg(CANSHU_ERROR);
            return $msg;
        }

        $order_info  = $this->order->where(['order_id'=>$order_id])->find();
        if(empty($order_info)){
            $msg['message']=checkMsg(ORDER_NOT_EXIT);
            return $msg;
        }
        $payRequestBuilder = new \AlipayTradePagePayContentBuilder();
        //商户订单号，商户网站订单系统中唯一订单号，必填
        $out_trade_no = $order_info['order_sn'];

        //订单名称，必填
        $subject = '遇策商城订单';

        //付款金额，必填
        $total_amount = $order_info['order_pay_amount'];
        //商品描述，可空
        $body = '商品描述';
        //构造参数
        $payRequestBuilder->setBody($body);
        $payRequestBuilder->setSubject($subject);
        $payRequestBuilder->setTotalAmount($total_amount);
        $payRequestBuilder->setOutTradeNo($out_trade_no);
         $config=$this->order->alipay_config();
        //电脑网站支付请求
        $aop = new \AlipayTradeService($config);
        $response = $aop->pagePay($payRequestBuilder,$config['return_url'],$config['notify_url']);
        var_dump($response);
    }

}